package com.onlocation.objects;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import com.onlocation.R;

/**
 * Author: Steve Carrell
 * Date: 5/10/12
 */
public class OkCancelDialog {
    AlertDialog.Builder dialog;

    public OkCancelDialog(Context packageContext) {
        init(packageContext, "", "");
    }

    public OkCancelDialog(Context packageContext, String title) {
        init(packageContext, title, "");
    }

    public OkCancelDialog(Context packageContext, String title, String text) {
        init(packageContext, title, text);
    }
    
    private void init(Context packageContext, String title, String text) {
        dialog = new AlertDialog.Builder(packageContext);
        dialog.setTitle(title);
        dialog.setMessage(text);

        setButtons();
        setCancelable(true);
    }

    public void setCancelable(boolean cancelable) {
        dialog.setCancelable(cancelable);
        if (cancelable) {
            dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    cancelAction();
                }
            });
        }
    }
    
    protected void setButtons() {
        dialog.setPositiveButton(R.string.okBtn, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                okAction();
            }
        });
        
        dialog.setNegativeButton(R.string.cancelBtn, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                cancelAction();
            }
        });
    }
    
    protected void okAction() {
        
    }

    protected void cancelAction() {

    }

    public void show() {
        dialog.create().show();
    }
}
